<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>zgehrd.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="ZGEHRD.1"></a><a href="zgehrd.f.html#ZGEHRD.1">ZGEHRD</a>( N, ILO, IHI, A, LDA, TAU, WORK, LWORK, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      INTEGER            IHI, ILO, INFO, LDA, LWORK, N
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      COMPLEX*16        A( LDA, * ), TAU( * ), WORK( * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="ZGEHRD.17"></a><a href="zgehrd.f.html#ZGEHRD.1">ZGEHRD</a> reduces a complex general matrix A to upper Hessenberg form H by
</span><span class="comment">*</span><span class="comment">  an unitary similarity transformation:  Q' * A * Q = H .
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The order of the matrix A.  N &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  ILO     (input) INTEGER
</span><span class="comment">*</span><span class="comment">  IHI     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          It is assumed that A is already upper triangular in rows
</span><span class="comment">*</span><span class="comment">          and columns 1:ILO-1 and IHI+1:N. ILO and IHI are normally
</span><span class="comment">*</span><span class="comment">          set by a previous call to <a name="ZGEBAL.30"></a><a href="zgebal.f.html#ZGEBAL.1">ZGEBAL</a>; otherwise they should be
</span><span class="comment">*</span><span class="comment">          set to 1 and N respectively. See Further Details.
</span><span class="comment">*</span><span class="comment">          1 &lt;= ILO &lt;= IHI &lt;= N, if N &gt; 0; ILO=1 and IHI=0, if N=0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  A       (input/output) COMPLEX*16 array, dimension (LDA,N)
</span><span class="comment">*</span><span class="comment">          On entry, the N-by-N general matrix to be reduced.
</span><span class="comment">*</span><span class="comment">          On exit, the upper triangle and the first subdiagonal of A
</span><span class="comment">*</span><span class="comment">          are overwritten with the upper Hessenberg matrix H, and the
</span><span class="comment">*</span><span class="comment">          elements below the first subdiagonal, with the array TAU,
</span><span class="comment">*</span><span class="comment">          represent the unitary matrix Q as a product of elementary
</span><span class="comment">*</span><span class="comment">          reflectors. See Further Details.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDA     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array A.  LDA &gt;= max(1,N).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  TAU     (output) COMPLEX*16 array, dimension (N-1)
</span><span class="comment">*</span><span class="comment">          The scalar factors of the elementary reflectors (see Further
</span><span class="comment">*</span><span class="comment">          Details). Elements 1:ILO-1 and IHI:N-1 of TAU are set to
</span><span class="comment">*</span><span class="comment">          zero.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  WORK    (workspace/output) COMPLEX*16 array, dimension (LWORK)
</span><span class="comment">*</span><span class="comment">          On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LWORK   (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The length of the array WORK.  LWORK &gt;= max(1,N).
</span><span class="comment">*</span><span class="comment">          For optimum performance LWORK &gt;= N*NB, where NB is the
</span><span class="comment">*</span><span class="comment">          optimal blocksize.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">          If LWORK = -1, then a workspace query is assumed; the routine
</span><span class="comment">*</span><span class="comment">          only calculates the optimal size of the WORK array, returns
</span><span class="comment">*</span><span class="comment">          this value as the first entry of the WORK array, and no error
</span><span class="comment">*</span><span class="comment">          message related to LWORK is issued by <a name="XERBLA.61"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO    (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0:  successful exit
</span><span class="comment">*</span><span class="comment">          &lt; 0:  if INFO = -i, the i-th argument had an illegal value.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Further Details
</span><span class="comment">*</span><span class="comment">  ===============
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  The matrix Q is represented as a product of (ihi-ilo) elementary
</span><span class="comment">*</span><span class="comment">  reflectors
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Q = H(ilo) H(ilo+1) . . . H(ihi-1).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Each H(i) has the form
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     H(i) = I - tau * v * v'
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  where tau is a complex scalar, and v is a complex vector with
</span><span class="comment">*</span><span class="comment">  v(1:i) = 0, v(i+1) = 1 and v(ihi+1:n) = 0; v(i+2:ihi) is stored on
</span><span class="comment">*</span><span class="comment">  exit in A(i+2:ihi,i), and tau in TAU(i).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  The contents of A are illustrated by the following example, with
</span><span class="comment">*</span><span class="comment">  n = 7, ilo = 2 and ihi = 6:
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  on entry,                        on exit,
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  ( a   a   a   a   a   a   a )    (  a   a   h   h   h   h   a )
</span><span class="comment">*</span><span class="comment">  (     a   a   a   a   a   a )    (      a   h   h   h   h   a )
</span><span class="comment">*</span><span class="comment">  (     a   a   a   a   a   a )    (      h   h   h   h   h   h )
</span><span class="comment">*</span><span class="comment">  (     a   a   a   a   a   a )    (      v2  h   h   h   h   h )
</span><span class="comment">*</span><span class="comment">  (     a   a   a   a   a   a )    (      v2  v3  h   h   h   h )
</span><span class="comment">*</span><span class="comment">  (     a   a   a   a   a   a )    (      v2  v3  v4  h   h   h )
</span><span class="comment">*</span><span class="comment">  (                         a )    (                          a )
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  where a denotes an element of the original matrix A, h denotes a
</span><span class="comment">*</span><span class="comment">  modified element of the upper Hessenberg matrix H, and vi denotes an
</span><span class="comment">*</span><span class="comment">  element of the vector defining H(i).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  This file is a slight modification of LAPACK-3.0's <a name="ZGEHRD.100"></a><a href="zgehrd.f.html#ZGEHRD.1">ZGEHRD</a>
</span><span class="comment">*</span><span class="comment">  subroutine incorporating improvements proposed by Quintana-Orti and
</span><span class="comment">*</span><span class="comment">  Van de Geijn (2005). 
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      INTEGER            NBMAX, LDT
      PARAMETER          ( NBMAX = 64, LDT = NBMAX+1 )
      COMPLEX*16        ZERO, ONE
      PARAMETER          ( ZERO = ( 0.0D+0, 0.0D+0 ), 
     $                     ONE = ( 1.0D+0, 0.0D+0 ) )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      LOGICAL            LQUERY
      INTEGER            I, IB, IINFO, IWS, J, LDWORK, LWKOPT, NB,
     $                   NBMIN, NH, NX
      COMPLEX*16        EI
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Arrays ..
</span>      COMPLEX*16        T( LDT, NBMAX )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           ZAXPY, <a name="ZGEHD2.123"></a><a href="zgehd2.f.html#ZGEHD2.1">ZGEHD2</a>, ZGEMM, <a name="ZLAHR2.123"></a><a href="zlahr2.f.html#ZLAHR2.1">ZLAHR2</a>, <a name="ZLARFB.123"></a><a href="zlarfb.f.html#ZLARFB.1">ZLARFB</a>, ZTRMM,
     $                   <a name="XERBLA.124"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          MAX, MIN
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      INTEGER            <a name="ILAENV.130"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>
      EXTERNAL           <a name="ILAENV.131"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Test the input parameters
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
      NB = MIN( NBMAX, <a name="ILAENV.138"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 1, <span class="string">'<a name="ZGEHRD.138"></a><a href="zgehrd.f.html#ZGEHRD.1">ZGEHRD</a>'</span>, <span class="string">' '</span>, N, ILO, IHI, -1 ) )
      LWKOPT = N*NB
      WORK( 1 ) = LWKOPT
      LQUERY = ( LWORK.EQ.-1 )
      IF( N.LT.0 ) THEN
         INFO = -1
      ELSE IF( ILO.LT.1 .OR. ILO.GT.MAX( 1, N ) ) THEN
         INFO = -2
      ELSE IF( IHI.LT.MIN( ILO, N ) .OR. IHI.GT.N ) THEN
         INFO = -3
      ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
         INFO = -5
      ELSE IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
         INFO = -8
      END IF
      IF( INFO.NE.0 ) THEN
         CALL <a name="XERBLA.154"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="ZGEHRD.154"></a><a href="zgehrd.f.html#ZGEHRD.1">ZGEHRD</a>'</span>, -INFO )
         RETURN
      ELSE IF( LQUERY ) THEN
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Set elements 1:ILO-1 and IHI:N-1 of TAU to zero
</span><span class="comment">*</span><span class="comment">
</span>      DO 10 I = 1, ILO - 1
         TAU( I ) = ZERO
   10 CONTINUE
      DO 20 I = MAX( 1, IHI ), N - 1
         TAU( I ) = ZERO
   20 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Quick return if possible
</span><span class="comment">*</span><span class="comment">
</span>      NH = IHI - ILO + 1
      IF( NH.LE.1 ) THEN
         WORK( 1 ) = 1
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Determine the block size
</span><span class="comment">*</span><span class="comment">
</span>      NB = MIN( NBMAX, <a name="ILAENV.179"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 1, <span class="string">'<a name="ZGEHRD.179"></a><a href="zgehrd.f.html#ZGEHRD.1">ZGEHRD</a>'</span>, <span class="string">' '</span>, N, ILO, IHI, -1 ) )
      NBMIN = 2
      IWS = 1
      IF( NB.GT.1 .AND. NB.LT.NH ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Determine when to cross over from blocked to unblocked code
</span><span class="comment">*</span><span class="comment">        (last block is always handled by unblocked code)
</span><span class="comment">*</span><span class="comment">
</span>         NX = MAX( NB, <a name="ILAENV.187"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 3, <span class="string">'<a name="ZGEHRD.187"></a><a href="zgehrd.f.html#ZGEHRD.1">ZGEHRD</a>'</span>, <span class="string">' '</span>, N, ILO, IHI, -1 ) )
         IF( NX.LT.NH ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Determine if workspace is large enough for blocked code
</span><span class="comment">*</span><span class="comment">
</span>            IWS = N*NB
            IF( LWORK.LT.IWS ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Not enough workspace to use optimal NB:  determine the
</span><span class="comment">*</span><span class="comment">              minimum value of NB, and reduce NB or force use of
</span><span class="comment">*</span><span class="comment">              unblocked code
</span><span class="comment">*</span><span class="comment">
</span>               NBMIN = MAX( 2, <a name="ILAENV.199"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 2, <span class="string">'<a name="ZGEHRD.199"></a><a href="zgehrd.f.html#ZGEHRD.1">ZGEHRD</a>'</span>, <span class="string">' '</span>, N, ILO, IHI,
     $                 -1 ) )
               IF( LWORK.GE.N*NBMIN ) THEN
                  NB = LWORK / N
               ELSE
                  NB = 1
               END IF
            END IF
         END IF
      END IF
      LDWORK = N
<span class="comment">*</span><span class="comment">
</span>      IF( NB.LT.NBMIN .OR. NB.GE.NH ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Use unblocked code below
</span><span class="comment">*</span><span class="comment">
</span>         I = ILO
<span class="comment">*</span><span class="comment">
</span>      ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Use blocked code
</span><span class="comment">*</span><span class="comment">
</span>         DO 40 I = ILO, IHI - 1 - NX, NB
            IB = MIN( NB, IHI-I )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Reduce columns i:i+ib-1 to Hessenberg form, returning the
</span><span class="comment">*</span><span class="comment">           matrices V and T of the block reflector H = I - V*T*V'
</span><span class="comment">*</span><span class="comment">           which performs the reduction, and also the matrix Y = A*V*T
</span><span class="comment">*</span><span class="comment">
</span>            CALL <a name="ZLAHR2.228"></a><a href="zlahr2.f.html#ZLAHR2.1">ZLAHR2</a>( IHI, I, IB, A( 1, I ), LDA, TAU( I ), T, LDT,
     $                   WORK, LDWORK )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Apply the block reflector H to A(1:ihi,i+ib:ihi) from the
</span><span class="comment">*</span><span class="comment">           right, computing  A := A - Y * V'. V(i+ib,ib-1) must be set
</span><span class="comment">*</span><span class="comment">           to 1
</span><span class="comment">*</span><span class="comment">
</span>            EI = A( I+IB, I+IB-1 )
            A( I+IB, I+IB-1 ) = ONE
            CALL ZGEMM( <span class="string">'No transpose'</span>, <span class="string">'Conjugate transpose'</span>, 
     $                  IHI, IHI-I-IB+1,
     $                  IB, -ONE, WORK, LDWORK, A( I+IB, I ), LDA, ONE,
     $                  A( 1, I+IB ), LDA )
            A( I+IB, I+IB-1 ) = EI
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Apply the block reflector H to A(1:i,i+1:i+ib-1) from the
</span><span class="comment">*</span><span class="comment">           right
</span><span class="comment">*</span><span class="comment">
</span>            CALL ZTRMM( <span class="string">'Right'</span>, <span class="string">'Lower'</span>, <span class="string">'Conjugate transpose'</span>,
     $                  <span class="string">'Unit'</span>, I, IB-1,
     $                  ONE, A( I+1, I ), LDA, WORK, LDWORK )
            DO 30 J = 0, IB-2
               CALL ZAXPY( I, -ONE, WORK( LDWORK*J+1 ), 1,
     $                     A( 1, I+J+1 ), 1 )
   30       CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Apply the block reflector H to A(i+1:ihi,i+ib:n) from the
</span><span class="comment">*</span><span class="comment">           left
</span><span class="comment">*</span><span class="comment">
</span>            CALL <a name="ZLARFB.257"></a><a href="zlarfb.f.html#ZLARFB.1">ZLARFB</a>( <span class="string">'Left'</span>, <span class="string">'Conjugate transpose'</span>, <span class="string">'Forward'</span>,
     $                   <span class="string">'Columnwise'</span>,
     $                   IHI-I, N-I-IB+1, IB, A( I+1, I ), LDA, T, LDT,
     $                   A( I+1, I+IB ), LDA, WORK, LDWORK )
   40    CONTINUE
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Use unblocked code to reduce the rest of the matrix
</span><span class="comment">*</span><span class="comment">
</span>      CALL <a name="ZGEHD2.266"></a><a href="zgehd2.f.html#ZGEHD2.1">ZGEHD2</a>( N, I, IHI, A, LDA, TAU, WORK, IINFO )
      WORK( 1 ) = IWS
<span class="comment">*</span><span class="comment">
</span>      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="ZGEHRD.271"></a><a href="zgehrd.f.html#ZGEHRD.1">ZGEHRD</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
